<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="/WEB-INF/templates/general.xhtml">
        
        <ui:define name="title"><h:outputText value="Orders" /></ui:define>

        <ui:define name="content">
        <h:form id="form">
       	 	
       	 	<p:remoteCommand update="table" autoRun="true" actionListener="#{orderBean.refreshOrders()}"/>   
       	 	
        	<p:growl id="growl" showDetail="false" life="3000" autoUpdate="true" />
			
			<p:remoteCommand name="search" actionListener="#{orderBean.search}" update="table" />
			
			<p:commandButton value="New order" id="newOrder" action="newOrder" actionListener="#{orderBean.reset()}" style="margin: 10px;" styleClass="btn btn-success">
				<f:setPropertyActionListener target="#{orderBean.edit}" value="#{false}" />
				<f:setPropertyActionListener target="#{orderBean.currentOrder}" value="#{null}" />
			</p:commandButton>

			<div style="width:35px; float:right; margin-top: 7px;">
				<p:commandLink id="search" style="margin: 0px auto;" actionListener="#{orderBean.search}" update="table">
					<p:graphicImage value="/images/search-icon.png" styleClass="search-icon" width="30px"/>
				</p:commandLink>
			</div>
			<p:inputText id="find" value="#{orderBean.find}" onkeypress="if (event.keyCode == 13){ search(); return false;}" style="float:right; margin: 10px; width: 200px;" update="table">
			</p:inputText>
			<p:watermark for="find" value="Search..." />  

			<p:dataTable id="table" value="#{orderBean.filteredOrders}" var="order" style="font-size: 14px; text-align: center;" styleClass="tableWhiteSpace orderTable newTableHeader"
                         scrollable="true" liveScroll="true" scrollHeight="450" scrollRows="25">

				
				<p:column headerText="Status" styleClass="phase, #{orderBean.style(order)}" width="10">
					#{orderBean.getStatusName(order.t)}
				</p:column>
				<p:column headerText="Ocnr." width="10">
					#{order.orderData.ocnr}
				</p:column>
				<p:column headerText="Company" width="10">
					#{order.orderData.company}
				</p:column>
				<p:column headerText="Purchase Order Number." width="10">
					#{order.orderData.ordernr}
				</p:column>
				<p:column headerText="Order Date" width="10">
					#{order.orderData.odate}
				</p:column>
				<p:column headerText="Planned Delivery Date" width="10">
					#{order.orderData.ddate}
				</p:column>
				<p:column headerText="Actual Delivery Date" width="10">
					#{order.orderData.addate}
				</p:column>
				<p:column headerText="O1" width="10">
					<p:commandLink actionListener="#{orderBean.setOrderForEdit(order)}" action="newOrder">
						<f:setPropertyActionListener target="#{orderBean.edit}" value="#{true}" />
						<h:graphicImage value="/images/doc.png" width="30"/>
					</p:commandLink>
				</p:column>
				<p:column headerText="O2" width="10">
					<p:commandLink rendered="#{order.t >= 1}" actionListener="#{orderBean.setOrderForEdit(order)}" action="continue">
						<h:graphicImage value="/images/doc.png" width="30"/>
					</p:commandLink>
				</p:column>
				<p:column headerText="P1" width="10">
					<p:commandLink action="form1">
						<h:graphicImage value="/images/print.png" width="20"/>
						<f:setPropertyActionListener target="#{orderBean.currentOrder}" value="#{order}" />
					</p:commandLink>
				</p:column>
				<p:column headerText="P2" width="10">
					<p:commandLink action="form2">
						<h:graphicImage value="/images/print.png" width="20"/>
						<f:setPropertyActionListener target="#{orderBean.currentOrder}" value="#{order}" />
					</p:commandLink>
				</p:column>
				<p:column headerText="P3" width="10">
					<p:commandLink action="form3">
						<h:graphicImage value="/images/print.png" width="20"/>
						<f:setPropertyActionListener target="#{orderBean.currentOrder}" value="#{order}" />
					</p:commandLink>
				</p:column>
				<p:column headerText="Del" width="10">
					<p:commandLink oncomplete="warnDialog.show()">
						<f:setPropertyActionListener target="#{orderBean.orderToDelete}" value="#{order}" />
						<h:graphicImage value="/images/delete.png" width="25"/>
					</p:commandLink>
				</p:column>
			</p:dataTable>

			<p:dialog widgetVar="warnDialog" modal="true" header="Delete Order" resizable="false">
				<p:panelGrid styleClass="noBorder" columns="2">
					<p:column colspan="2">
						<h:outputText value="Are you sure you want to delete this order?" />
					</p:column>
					<p:column></p:column>
					<p:column>
						<p:commandButton value="Yes" oncomplete="warnDialog.hide()" update="form" actionListener="#{orderBean.delete}" styleClass="btn btn-success" />
						<p:commandButton value="No" oncomplete="warnDialog.hide()" styleClass="btn btn-danger"/>
					</p:column>
				</p:panelGrid>
			</p:dialog>
			
        </h:form>
        </ui:define>
        
</ui:composition>